package ventanas;
import java.awt.CardLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;

import javax.swing.AbstractListModel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.ListSelectionEvent;

import clasesBasicas.Global;
import java.awt.Component;


public class PanelEste extends JPanel {
	private JList<String> list;
	private boolean pulsado;

	/**
	 * Create the panel.
	 */
	public PanelEste() {
		setPreferredSize(new Dimension(60, 10));
		setMinimumSize(new Dimension(80, 80));
		setLayout(new CardLayout(0, 0));
		JPanel panel = new JPanel();
		panel.setAlignmentY(Component.BOTTOM_ALIGNMENT);
		FlowLayout flowLayout = (FlowLayout) panel.getLayout();
		flowLayout.setAlignOnBaseline(true);
		panel.setPreferredSize(new Dimension(40, 200));
		panel.setMinimumSize(new Dimension(40, 200));
		panel.setMaximumSize(new Dimension(40, 200));
		add(panel, "listaEmpresasLat");
		this.setLocation(0, 20);

		list = new JList<String>();
		list.setAlignmentY(Component.BOTTOM_ALIGNMENT);
		list.addListSelectionListener(new ListSelectionListener() {
			public void valueChanged(ListSelectionEvent arg0) {
				if(!pulsado)
				{
				pulsado=true;
//				clasesBasicas.Global.cod_Emp_Sel=list.getSelectedIndex()+1;
				System.out.println("AQUI------------------------------------------");
				String temp=list.getSelectedValue();
				Global.pEmp.removerGrafico();
				switch (temp)
				{
				case "ABE":clasesBasicas.Global.cod_Emp_Sel=1;
				break;
				case "ANA":clasesBasicas.Global.cod_Emp_Sel=2;
				break;
				case "ACS":clasesBasicas.Global.cod_Emp_Sel=3;
				break;
				case "AMS":clasesBasicas.Global.cod_Emp_Sel=4;
				break;
				case "MTS":clasesBasicas.Global.cod_Emp_Sel=5;
				break;
				case "SAB":clasesBasicas.Global.cod_Emp_Sel=6;
				break;
				case "SAN":clasesBasicas.Global.cod_Emp_Sel=7;
				break;
				case "BKIA":clasesBasicas.Global.cod_Emp_Sel=8;
				break;
				case "BKT":clasesBasicas.Global.cod_Emp_Sel=9;
				break;
				case "BBVA":clasesBasicas.Global.cod_Emp_Sel=10;
				break;
				case "POP":clasesBasicas.Global.cod_Emp_Sel=11;
				break;
				case "BME":clasesBasicas.Global.cod_Emp_Sel=12;
				break;
				case "CABK":clasesBasicas.Global.cod_Emp_Sel=13;
				break;
				case "DIA":clasesBasicas.Global.cod_Emp_Sel=14;
				break;
				case "EBRO":clasesBasicas.Global.cod_Emp_Sel=15;
				break;
				case "ENG":clasesBasicas.Global.cod_Emp_Sel=16;
				break;
				case "FER":clasesBasicas.Global.cod_Emp_Sel=17;
				break;
				case "FCC":clasesBasicas.Global.cod_Emp_Sel=18;
				break;
				case "GAM":clasesBasicas.Global.cod_Emp_Sel=19;
				break;
				case "GAS":clasesBasicas.Global.cod_Emp_Sel=20;
				break;
				case "GRF":clasesBasicas.Global.cod_Emp_Sel=21;
				break;
				case "IBE":clasesBasicas.Global.cod_Emp_Sel=22;
				break;
				case "ITX":clasesBasicas.Global.cod_Emp_Sel=23;
				break;
				case "IDR":clasesBasicas.Global.cod_Emp_Sel=24;
				break;
				case "IAG":clasesBasicas.Global.cod_Emp_Sel=25;
				break;
				case "JAZ":clasesBasicas.Global.cod_Emp_Sel=26;
				break;
				case "MAP":clasesBasicas.Global.cod_Emp_Sel=27;
				break;
				case "TL5":clasesBasicas.Global.cod_Emp_Sel=28;
				break;
				case "OHL":clasesBasicas.Global.cod_Emp_Sel=29;
				break;
				case "REE":clasesBasicas.Global.cod_Emp_Sel=30;
				break;
				case "REP":clasesBasicas.Global.cod_Emp_Sel=31;
				break;
				case "SCYR":clasesBasicas.Global.cod_Emp_Sel=32;
				break;
				case "TRE":clasesBasicas.Global.cod_Emp_Sel=33;
				break;
				case "TEF":clasesBasicas.Global.cod_Emp_Sel=34;
				break;
				case "VIS":clasesBasicas.Global.cod_Emp_Sel=35;
				break;
				}
				
				Thread actualizar= new Thread(new Runnable() {
						
						@Override
						public void run() {
							clasesBasicas.Global.pEmp.actualizarPEmpresa();
						}
				});
				actualizar.start();
				if(Global.sU.usuarioActual!=null)
				{
				Global.pEmp.actualizarMaximos();
				}
				Global.pEmp.setVisible(true);
				Global.pNot.setVisible(false);
				Global.pLista.setVisible(false);
				if(Global.pFav != null){
					
					Global.pFav.setVisible(false);
					Global.pRan.apagarCancion();
				}
				if(Global.pRan != null){
					
					Global.pRan.setVisible(false);	
				}
				if(Global.pPref!=null)
				{
					Global.pPref.setVisible(false);
				}
				if(Global.pAdministrar != null){
					Global.pAdministrar.setVisible(false);
				}
				
				if(Global.pMovimientos != null){
					Global.pMovimientos.setVisible(false);
				}

				pulsado=false;
				}
			}
		});
		
		panel.add(list);
		list.setFixedCellHeight(18);
		list.setFont(new Font("Tahoma", Font.PLAIN, 12));
		list.setSize(new Dimension(40, 500));
		list.setMinimumSize(new Dimension(40, 650));
		list.setMaximumSize(new Dimension(40, 650));
		list.setPreferredSize(new Dimension(40, 650));
		list.setVisibleRowCount(35);
		list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		
		list.setModel(new AbstractListModel() {
			String[] values = new String[] {"ABE", "ANA", "ACS", "AMS", "MTS", "SAB", "SAN", "BKIA", "BKT", "BBVA", "POP", "BME", "CABK", "DIA", "EBRO", "ENG", "FER", "FCC", "GAM", "GAS", "GRF", "IBE", "ITX", "IDR", "IAG", "JAZ", "MAP", "TL5", "OHL", "REE", "REP", "SCYR", "TRE", "TEF", "VIS"};
			public int getSize() {
				return values.length;
			}
			public Object getElementAt(int index) {
				return values[index];
			}
		});

	}

}
